package com.objectdraw.client.objectdraw;
//import java.awt.*;
import java.awt.event.*;
//import java.util.EventListener;

/**
 * defines actions for keyboard actions
 */
public class KeyboardListener  
implements KeyListener { 

	protected DrawingCanvas canvas;

	/**
	 * instantiates keyboard listener
	 * @param canvas where the listener is listening
	 */
	public KeyboardListener(DrawingCanvas canvas) {
		this.canvas = canvas;
	}

	/**
	 * takes keypresses and passes them to the current tool
	 * also sends the message "key " + the char in the event
	 */
	public void keyPressed(KeyEvent e) {
		KeyboardTool tool = (KeyboardTool)canvas.getCurrentTool();
		if (tool != null && canvas.control) {
			tool.keyPressed(e);
			canvas.com.sendMessage("key "+e.getKeyChar());
		}
	}

	/**
	 * unimplemented
	 */
	public void keyReleased(KeyEvent e) { 
//		KeyboardTool tool = (KeyboardTool)canvas.getCurrentTool();
//		if(tool != null && canvas.control) {
//			tool.keyReleased(e);
//			canvas.com.sendMessage("key released "+e.getKeyChar());
//		}
	}
	/**
	 * unimplemented
	 */
	public void keyTyped(KeyEvent e) {
//		KeyboardTool tool = (KeyboardTool)canvas.getCurrentTool();
//		if(tool != null && canvas.control) {
//			tool.keyTyped(e);
//			canvas.com.sendMessage("key typed "+e.getKeyChar());
//		}
	}

}
